<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="cn.com.generaldata.os.constant.ReportConstant" %>
<%@ include file="/static/include/top.jsp"%>
<!--
待审核模块
模块作用：省区级用户对所有企业上报报表进行首次审核，审核后报表会进入待提交，和待驳回列表。
注：替企业填报的报表也会提交到这里。
-->
<c:set var="title" value=""></c:set>
<c:set var="provinceArea" value="<%=ReportConstant.PROVINCE_AREA_ID%>"></c:set>
<c:if test="${requestScope.checkStatus eq '1'}">
	<c:set var="title" value="审核"></c:set>
</c:if>
<c:if test="${requestScope.checkStatus eq '55'}">
	<c:set var="title" value="终审核"></c:set>
</c:if>

<script>document.title="${title}";</script>
<script src="${baseURL}/static/js/My97DatePicker/WdatePicker.js"></script>
<table>
		<tbody>
			<tr>
				<th><img src="${ctx}/static/images/pages/cen/rig/ico_01.png" align="middle">&nbsp;${title}
				</th>
			</tr>
			<tr class="tab_grey">
				<td>
	<form name="searchForm" action="" method="post">
			<input type="hidden" name="p" value="1" />
			报表制度:
		<select id="typeId" name="typeId" onchange="getVersion($('#typeId').val());"  class="tab_textbut" >
			<option value="">请选择..</option>
			<c:forEach var="sys" items="${requestScope.sysCodeList}">					
                 	<option value="${sys.code}">${sys.codeName}</option>
            </c:forEach>
		</select>
		
		<span class="tab_text">报表版本:</span>
		<select id="versionId" name="versionId" onchange="getRep($('#typeId').val(),$('#versionId').val());"  class="tab_textbut_200" >
			<option value="">请选择..</option>
			<c:forEach var="vs" items="${vsList}">
                   <option value="${vs.id}">${vs.versionSystem}</option>
               </c:forEach>
		</select>
				
		<span class="tab_text">填报报表:</span>
		<select id="reportTypeId" name="reportTypeId" class="tab_textbut_300" >
			<option value="" id="">请选择..</option>
        </select>
		<span class="tab_text">填报单位名称：</span>
			<input type="text" name="unitName" id="unitName" value="${param['unitName']}" size="20"  class="tab_textbut"/>
		<br/>
		
		<span class="tab_text">报表年份：</span>
			<select style="width:70px" id="createYear" name="createYear" class="tab_textbut">
               <c:forEach var="year" items="${requestScope.yearList}">
                   <option value="${year}" <c:if test="${curYear == year}">selected</c:if>>${year}</option>
               </c:forEach>
           </select>
        	
        <span class="tab_text">开始时间:</span>
		<input id="searchDate" name="searchDate" onfocus="WdatePicker()" class="Wdate"	value="${formdata.startTime}" type="text">
		<span class="tab_text">结束时间：</span>
		<input id="endDate" name="endDate" onfocus="WdatePicker()" class="Wdate" value="${formdata.endTime}" type="text"  class="tab_textbut" >
		
		
		<a class="tab_but" href="#" onclick="searchForm.action='${baseURL}/audit/webList/${requestScope.checkStatus}';searchForm.submit();return false;">查询</a>
		<a class="tab_but" href="#" onclick="clearInput(); return false;">清空结果</a>
		<c:if test="${requestScope.checkStatus eq '55'}">
		<a class="tab_but" href="#" onclick="submitSelects();return false;">上报选中</a>
		</c:if>
			<c:if test="${requestScope.checkStatus eq '1'}">
			<br/>
			<a class="tab_but02" href="#" onclick="searchYhqy();return false;">报表汇总审核查询</a>
			<a class="tab_but02" href="#" onclick="yhqyExp();return false;">汇总报表导出</a>	
		<br/>
			<c:if test="${sessionScope.user.userAreaId eq provinceArea}">
			<img src="${baseURL}/static/images/tab/ico.png" width="20" height="10" />审核意见：
			<textarea id="checkComment" name="checkComment" style="width:350px;"></textarea>
			<a class="tab_but02" href="#" onclick="multiPass(5);return false;">批量审核通过</a>
			<a class="tab_but02" href="#" onclick="multiPass(3);return false;">批量审核驳回</a>
			</c:if>
		</c:if>
	</form>
				</td>
			</tr>
		</tbody>
</table>

<c:if test="${empty obj.operationResult}">
	<b>没有符合条件的记录。</b>
</c:if>

<c:if test="${not empty obj.operationResult}">
<table id="listTable">
	<thead>
	    <tr>
			<th width="3%"><input type="checkbox" onclick="selectAll(this.checked);"></th>
	        <th width="20%">数据报表</th>
	        <th width="8%">地区</th>
			<th width="8%">频率</th>
			<th width="8%">报表年份</th>
			<th width="10%">报出时间</th>
			<th width="20%">报表单位</th>
			<th width="8%">填表人</th>
			<th width="8%">审批历史</th>
			<th>操作</th>
	    </tr>
	</thead>
	<tbody>
		<c:forEach var="report" items="${obj.operationResult}">
			<tr>
				<td align="left"><input name="chk" type="checkbox" id="chk" value="${report.id}" /></td>
		      	<td align="left">${report.reportName}</td>
		      	<td align="left">${report.reportCityName}</td>
				<td align="left">${requestScope.reportTimetype[report.reportTimetype]}</td>
				<td align="left">${report.reportYear}年</td>
				<td align="left"><fmt:formatDate value="${report.reportDate}" type="both" pattern="yyyy-MM-dd"/></td>
				<td align="left">${report.reportUnit}</td>
				<td align="left">${report.reportFillAdmin}</td>				
				<td align="left"><a href="#" onclick="reportHistoryView('${report.id}', '${report.reportUnit}', '${report.reportName}');">历史</a></td>
				<td align="left"><a href="#" onclick="reportView('${report.reportName}', '${report.id}');">详情</a></td>
			</tr>
		</c:forEach>
	</tbody>
	<tfoot>
		<tr class="tab_grey">
			<td colspan="10" align="center" valign="middle" class="tab_white">
				<div class="pagination"> 
					<%@ include file="../include/listpage2.jsp"%>
				</div>
				<div class="clear"></div>
				<form action="${ctx}/report/exportReport" method="post" id="exportForm" name="exportForm">
	</form>
			</td>
		</tr>
	</tfoot>
</table>
</c:if>

<script language="javaScript">

	//根据报表类型查询报表版本信息和表号信息
	function getVersion(typeId){		
		var versionObj = $("#versionId");
		var reportTypeObj = $("#reportTypeId");		
		
		initSelect(versionObj);	//初始化select
		initSelect(reportTypeObj);	//初始化select
		
		if (typeId!=""){
			//查询报表报表信息
			var v_url = "${baseURL}/company/report/queryReportVersion/" + typeId;
			$.ajax({			
				url:v_url,
				type:"post",
				dataType:"json",
				success:function(data){
					$.each(data.operationResult, function(i, item){						
						var selected = "";						
						if ("${param['versionId']}" == item.id){
							selected = "selected";
						}						
						versionObj.append("<option value='" + item.id + "' " + selected + " >" + item.versionSystem + "</option>");
					});
					
					versionObj.change();
				}
			});
		}
	}
	
	//根据报表类型查和报表版本查询所有的报表信息
	function getRep(typeId, versionId){		
		var reportTypeObj = $("#reportTypeId");	
		initSelect(reportTypeObj);	//初始化select
		if (typeId!=""&&versionId!=""){
			var url = "${baseURL}/company/report/queryReportTypesByParam/" + versionId + "/" + typeId;
			$.ajax({			
				url:url,
				type:"post",
				dataType:"json",
				success:function(data){					
					$.each(data, function(i, item){						
						var selected = "";						
						if ("${param['reportTypeId']}" == item.id){
							selected = "selected";
						}						
						reportTypeObj.append("<option id='"+item.newId+"' value='" + item.id + "' " + selected + ">" + item.typeName + "</option>");
					});
				}
			});
		}
	}	
	
	//初始化select
	function initSelect(s_obj){		
		s_obj.empty();		
		s_obj.append("<option value=''>请选择..</option>");		
	}
	
	//查看报表审批历史
	function reportHistoryView(reportId, reportUnit, reportName){
		  var title = "查看" + reportUnit + "的" + reportName + "的审批历史";
		  var url = "${baseURL}/data/view?id=" + reportId;
		  openWin(title, url, "800", "460");
	}
	
	//查看报表详情
	function reportView(reportName, reportId){
		var userId = "${sessionScope.user.id}";
		var title = reportName + "详情";
		var url = "${baseURL}/reports/service.do?method=showReportDetail&reportOperatorId=" + userId + "&reportId=" + reportId;
		openWin(title, url, "1000", "560");
	}

	function selectAll(checkAllFlag) {
		var checkArray = document.getElementsByName("chk");
		for (var i = 0; i < checkArray.length; i++) {
			checkArray[i].checked = checkAllFlag;
		}
	}
	
	function clearInput() {
		$("form input,form select").each(function(){
			this.value = "";
		});
		
		$("#listTable > tbody").html("");
		$("#listTable > tfoot").html("");
	}
	
	//上报选中
	function submitSelects(){
		var tids = "";
		var temp = document.getElementsByName("chk");
		for(var i=0;i<temp.length;i++){
	         if(temp[i].checked==true){
	         //alert(temp[i].value);
	         tids = tids + temp[i].value + ",";
	     }
	 	 }
		var dot = tids.lastIndexOf(",");
		if(dot == -1){
			layer.alert("请选择要提交的报表");
			return;
		}else {
			tids = tids.substring(0,dot);
		} 
		
		layer.confirm("确定要提交选中的报表吗？", function(){
			$.ajax({
				   type: "GET",
				   async: false,
				   url: '${baseURL}/audit/finalsubmit',
				   data: {ids : tids},
				   dataType: "json",
				   success: function(data){
			     	if(data.result=="OK"){
			     		layer.msg(data.message, 1, 1);
			     		window.location.href = window.location.href;
			     	}else{
			     		alert("上报失败，请重试");
			     		return;
			     	}
			}});
		});

	}
	
	/**************************初始化查询参数****************************/
	$("#typeId").val("${param['typeId']}");	
	if ($("#typeId").val() != ""){
		getVersion($("#typeId").val());
	}
	$("#unitName").val("${param['unitName']}");
	$("#createYear").val("${param['createYear']}");
	$("#reportTypeId").val("${param['reportTypeId']}");	
	$("#searchDate").val("${param['searchDate']}");
	$("#endDate").val("${param['endDate']}");
	/**************************初始化查询参数****************************/
	
	function searchYhqy() {
	if(!$("#typeId").val()) {
		layer.alert("请选择报表制度");
		return false;
	}
	if($("#reportTypeId").val()==0 || $("#reportTypeId").val()== null || $("#reportTypeId").val()== "") {
		layer.alert("请选择制度下的报表");
		return false;
	}
	var radius = $("#reportTypeId option:selected").attr("id");
	openWin("审核报表","${ctx}/audit/toVerify?checkStatus=1&reporTypeId="+$("#reportTypeId").val()+"&startingReportDate="+$("#searchDate").val()+"&endingReportDate="+$("#endDate").val()+"&flag=0&newTypeId="+radius+"&year="+$("#createYear").val(),1000,500,reload);

}

function yhqyExp(){
	if(!$("#typeId").val()) {
		layer.alert("请选择报表制度");
		return false;
	}
	if($("#reportTypeId").val()==0 || $("#reportTypeId").val()== null || $("#reportTypeId").val()== "") {
		layer.alert("请选择制度下的报表");
		return false;
	}
	var radius = $("#reportTypeId option:selected").attr("id");
	$('#exportForm').attr("action","${ctx}/audit/mutiExport?checkStatus=1&repId="+$("#reportTypeId").val()+"&startingReportDate="+$("#searchDate").val()+"&endingReportDate="+$("#endDate").val()+"&flag=0&showSum=true&repNewId="+radius+"&year="+$("#createYear").val());
	$("#exportForm").submit();
}

function reload(data) {
    alert(data);
    document.searchForm.submit();
}

function selectAll(checkAllFlag) {
	var checkArray = document.getElementsByName("chk");
	for (var i = 0; i < checkArray.length; i++) {
		checkArray[i].checked = checkAllFlag;
	}
}

function multiPass(ck)
{
	if (jQuery("input[name='chk']:checked").length < 1)
	{
		alert("请选择要审核的报表。");
		return;
	}
	var common=$("#checkComment").val();
	if(ck==3&&common=="")
	{
			alert("请填写审核意见。");
			return;	
	}
	var ids="";
	  var checkboxa = jQuery("input[name='chk']:checked").each(function(){
		  ids+=jQuery(this).val()+",";
	 });
	  var url = "${baseURL}/report/submit";
		var data = "checkStatus="+ck+"&ids="+ids+"&common="+common;

		var loadi;
		$.ajax({
			url: url,
			type: 'post',
			data: data,
			dataType: 'json',
			beforeSend: function(){
				loadi = layer.load('审核中…');
			},
			complete: function(){
				layer.close(loadi);
			},
			success: function(msg){
				reload(msg.message);
			}
		});	
}
</script>

<%@ include file="/static/include/bottom.jsp"%>